package cn.cnsy123.shorturls.api.controller.business;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.cnsy123.shorturls.api.controller.param.SysDeptInfoDeleteParam;
import cn.cnsy123.shorturls.api.controller.param.SysDeptInfoInsertParam;
import cn.cnsy123.shorturls.api.controller.param.SysDeptInfoQueryParam;
import cn.cnsy123.shorturls.api.controller.param.SysDeptUserTreeQueryParam;
import cn.cnsy123.shorturls.api.controller.vo.Select2ResultVo;
import cn.cnsy123.shorturls.api.controller.vo.SysDeptQueryResult;
import cn.cnsy123.shorturls.api.controller.vo.SysDeptSaveResult;
import cn.cnsy123.shorturls.api.controller.vo.ZtreeSimpleResultVo;
import cn.cnsy123.shorturls.business.service.SysDeptInfoService;

@Controller
@RequestMapping(value = "/sysDept")
public class SysDeptInfoController {
    
    private static final Logger logger = LoggerFactory.getLogger(SysDeptInfoController.class);
    
    @Autowired
    private SysDeptInfoService sysDeptInfoService;
    
    @RequestMapping(value = "/get",method = RequestMethod.GET)
    @ResponseBody
    public SysDeptQueryResult querySysDeptList(@RequestBody SysDeptInfoQueryParam sysDeptInfoQueryParam) {
        try {
            return sysDeptInfoService.querySysDeptList(sysDeptInfoQueryParam);
        } catch (Exception e) {
            logger.error("获取部门信息异常",e);
            return new SysDeptQueryResult(500, "查询部门信息异常");
        }
    }

    @RequestMapping(value = "/getTree",method = RequestMethod.GET)
    @ResponseBody
    public ZtreeSimpleResultVo querySysDeptTree() {
        try {
            return sysDeptInfoService.querySysDeptTree();
        } catch (Exception e) {
            logger.error("获取部门信息tree异常",e);
            return new ZtreeSimpleResultVo(500, "查询部门信息异常");
        }
    }
    
    
    @RequestMapping(value = "/getUserLeaderTree",method = RequestMethod.POST)
    @ResponseBody
    public Select2ResultVo querySysDeptLeaderTree(@RequestBody SysDeptUserTreeQueryParam sysDeptUserTreeQueryParam) {
        try {
            return sysDeptInfoService.querySysDeptLeaderTree(sysDeptUserTreeQueryParam);
        } catch (Exception e) {
            logger.error("获取部门人员信息异常",e);
            return new Select2ResultVo(500, "获取部门人员信息异常");
        }
    }
    
    
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public SysDeptSaveResult saveSysDeptInfo(@RequestBody SysDeptInfoInsertParam sysDeptInfoInsertParam) {
        try {
            return sysDeptInfoService.saveSysDeptInfo(sysDeptInfoInsertParam);
        } catch (Exception e) {
            logger.error("保存部门信息异常",e);
            return new SysDeptSaveResult(500,"保存部门信息异常");
        }
    }
    
    @RequestMapping(value = "/del",method = RequestMethod.DELETE)
    @ResponseBody
    public SysDeptSaveResult deleteSysDeptItem(SysDeptInfoDeleteParam sysDeptInfoDeleteParam) {
        try {
            return sysDeptInfoService.deleteSysDeptItem(sysDeptInfoDeleteParam);
        } catch (Exception e) {
            logger.error("删除部门信息异常",e);
            return new SysDeptSaveResult(500,"删除部门信息异常");
        }
    }
}
